package WizardTD.board;

import WizardTD.App;
import WizardTD.constant.Constant;
import lombok.Data;
import processing.core.PApplet;

/**
 * @author HustleLr
 * @version 1.0.0
 */
@Data
public class ManaProcessBar {
    private float manaCap;
    private float currentMana;
    private int count;

    public void subMana(float mana) {
        currentMana = Math.max(0, currentMana - mana);
    }

    public void upMana(float mana) {
        currentMana = Math.min(manaCap, currentMana + mana);
    }

    public void subManaPerSecond() {
        count++;
        if (count % 60 == 0) {
            this.currentMana += Constant.initialManaGainedPerSecond;
        }
    }

    public void draw(PApplet pApplet) {
        subManaPerSecond();
        float rectWidth = PApplet.map(currentMana, 0, manaCap, 0, App.CELLSIZE * 9);
        pApplet.fill(255);
        pApplet.rect(App.CELLSIZE * 14, 8, App.CELLSIZE * 9, App.CELLSIZE - 6);
        pApplet.fill(0, 206, 209);
        pApplet.rect(App.CELLSIZE * 14, 8, rectWidth, App.CELLSIZE - 6);
        pApplet.fill(0);
        pApplet.text(currentMana + "/" + manaCap, App.CELLSIZE * 15, App.CELLSIZE - 4);
    }
}
